<?php

namespace Modules\Production\Repository;

use App\Services\UnitService;
use Illuminate\Support\Facades\DB;
use Modules\Base\Repository\MaterialRepository;
use Modules\Production\Models\DassemblyOrder;
use Modules\Production\Models\DassemblyOrderDetail;

class DassemblyOrderDetailRepository
{

    /**
     * 组装拆卸单据头列表
     * @param $params
     * @return mixed
     */
    static public function getList($params){

        $builder = self::getWhere($params);

        $limit = isset($params['limit']) ? $params['limit'] : 100;

        return $builder->orderBy('id','desc')->with(['material'])->paginate($limit);

    }

    /**
     * 列表筛选条件拼接
     * @param $params
     * @return DassemblyOrder
     */
    static public function getWhere($params){

        $builder = new DassemblyOrderDetail();

        $canQueryField = $builder->getFields();
        foreach($params as $key => $val){
            if(!in_array($key,$canQueryField) || $val == ''){
                continue;
            }

            $builder = $builder->where($key,$val);

        }

        return $builder;

    }
}
